<!DOCTYPE html>
<html lang="en">
<head>
    <title>99支出单据</title>
    <#include "../inc/header.ftl"/>
</head>

<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <div class="row">
                    <div id="grid-main-data" class="col-xs-12">
                        <table id="MainGrid" style="min-height: 500px"></table>
                        <div id="toolbar">
                            <div style="padding:8px">
                                流水号：<input id="bankaffirmfind" class="easyui-textbox" style="width:140px">&emsp;
                                缴款账户： <input id="accountcode" name="accountcode">
                                缴款日期：<input id="paybankdtfind" class="easyui-datebox"  style="width:140px">&emsp;
                                <a href="#" onclick="javascript:searchInfo()" class="easyui-linkbutton"
                                   iconCls="icon-search">查 询</a>
                            </div>
                            <div style="padding:8px 8px 4px">
                                <a href="#" class="easyui-linkbutton" iconCls="icon-add"
                                   onclick="javascript:editInfo(1)">新增</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-edit"
                                   onclick="javascript:editInfo(2)">修改</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-cut"
                                   onclick="javascript:removeInfo()">删除</a>
                                <a href="#" class="easyui-linkbutton" iconCls="icon-send"
                                   onclick="javascript:sendInfo()">发送</a>


                            </div>
                        </div>
                    </div>
                </div><!-- /.row -->
            </div><!-- /.page-content -->
            <div id="box-update" class="ui-dialog-content hide" data-options="minimizable:true,maximizable:true">
                <form class="form-horizontal" id="form-update" method="post">
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">区划&nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="cantonid" id="cantonid" class="col-xs-12 easyui-textbox" data-options="required:true" style="width: 100%;"/>
                                    </span>
                        </div>
                        <input type="text" name="waitaffirmpayid" id="waitaffirmpayid" hidden/>
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">单位&nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="unitid" id="unitid" class="col-xs-12 easyui-textbox" data-options="required:true" style="width: 100%;">
                                    </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">项目</label>
                        <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="itemid" id="itemid" class="col-xs-12 easyui-textbox" data-options="required:true" style="width: 100%;">
                                    </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">缴款银行</label>
                        <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                         <input type="text" name="bankid" id="bankid" class="col-xs-12 easyui-textbox" data-options="required:true" style="width: 100%;"/>
                                    </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">缴款银行账号&nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" name="payeraccocunt" id="payeraccocunt"
                                               class="col-xs-12 easyui-textbox" readonly="true" style="width: 100%"/>
                                    </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款人账号 &nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                    <input type="text" name="payeeaccountnum" id="payeeaccountnum"
                                           class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%"/>
                                  </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款人&nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                      <input type="text" name="payeeaccountname" id="payeeaccountname"
                                             class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%"/>
                                  </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">金额&nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                    <input type="text" name="originfund" id="originfund"
                                           class="col-xs-12 easyui-numberbox" data-options="precision:2,required:true" style="width:100%"/>
                                  </span>
                        </div>

                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">收款时间&nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                  <span class="block input-icon input-icon-right">
                                    <input type="text" name="paybankdt" id="paybankdt"
                                           class="easyui-datetimebox col-xs-12 easyui-textbox" style="width:100%" data-options="required:true" />
                                  </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">交易流水号&nbsp;</label>
                        <div class="col-xs-12 col-sm-3">
                                    <span class="block input-icon input-icon-right">
                                      <input type="text" name="bankaffirm" id="bankaffirm"
                                             class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%"/>
                                     </span>
                        </div>
                        <label class="control-label col-xs-12 col-sm-1 no-padding-right">附言&nbsp;</label>
                        <div class="col-xs-12 col-sm-7">
                                  <span class="block input-icon input-icon-right">
                                    <input type="text" name="postscript" id="postscript"
                                           class="col-xs-12 easyui-textbox" data-options="required:true" style="width:100%"/>
                                  </span>
                        </div>

                    </div>

                </form>
            </div><!-- #dialog-confirm -->
            <#--发送-->
            <div id="SendBox-add" class="ui-dialog-content hide">
                <div style="padding:8px">
                    复核用户编码：<input id="usercode" class="easyui-textbox" style="width:110px" data-options="required:true" >&emsp;
                    复核用户密码：<input id="userpwd" class="easyui-passwordbox" style="width:110px" data-options="required:true" >&emsp;
                    <a href="#" class="easyui-linkbutton" iconCls="icon-redo"  onclick="javascript:pageSendInfo()"><span  id="sendClean"></span></a>
                </div>
                <table id="SendMainGrid"></table>
            </div>
        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->
<#include "../inc/basicjs.ftl"/>

<!-- inline scripts related to this page -->
<script type="text/javascript">

    jQuery(function ($) {
        // 右侧表格
        $('#MainGrid').datagrid({
            //title:'化解专户列表',
            url: prefix + '/bill/waitaffirmpayinfo/findWaitaffirmPayInfoPage',
            checkbox: true,
            pagination: true,
            fitColumns: false,
            striped: true,
            singleSelect: false,
            loadMsg: "正在加载数据，请稍后...",
            queryParams: {accountcode: '', paybankdt: '',bankaffirm:''},
            columns: [[
                {field: 'ck', checkbox: true},
                {title: '行政区划', field: 'cantonname', width: 80},
                {title: '付款单位', field: 'unitname'},
                {title: '付款项目', field: 'itemname'},
                {title: '付款户名', field: 'payerbank'},
                {title: '付款银行账号', field: 'payeraccount', width: 140},
                {title: '收款人', field: 'payeeaccountname'},
                {title: '收款人账号', field: 'payeeaccountnum', width: 140},
                {title: '金额', field: 'originfund', width: 80},
                {title: '交易日期', field: 'paybankdt', width: 130},
                {title: '流水号', field: 'bankaffirm'},
                {title: '附言', field: 'postscript', width: 100}
            ]],
            toolbar: '#toolbar',
            onBeforeLoad: function (param) {
                // 首次打开时，不加载数据
                var firstLoad = $(this).attr("firstLoad");  
                if (firstLoad == "false" || typeof (firstLoad) == "undefined") {  
                    $(this).attr("firstLoad","true");  
                    return false;  
                }  
                return true;  
            },
            onDblClickRow: function (index, data) {
                $('#form-update').form('load',data);
                $('#bankid').combogrid('disable');
                showForm(2);
            },
            onLoadSuccess: function (data) {
                if (data.total == 0) {
                    $('#grid-main-data').find('.datagrid-body').html('<div style="text-align: center;font-size: 14px;padding: 20px 0;">查询无数据</div>');
                }
            }
        });
        $(window).resize(function () {
            $('#MainGrid').datagrid('resize');
        });
        // 查询的下拉框
        $('#accountcode').combogrid({
            panelWidth:550,
            idField:'accountcode',
            textField:'accountcode',
            data: _bankdata,
            columns:[[
                {field: 'ck', checkbox: true},
                {field:'cantonname',title:'区划',width:80},
                {field:'accountcode',title:'账号',width:160},
                {field:'bankname',title:'开户行名称',width:260}
            ]]
        });
        // 编辑框，缴款银行
        $('#bankid').combogrid({
            panelMaxHeight: 200,
            panelWidth:600,
            idField:'bankid',
            textField:'accountname',
            data: _bankdata,
            editable: false,
            columns:[[
                {field:'accountcode',title:'收款人账号'},
                {field:'accountname',title:'收款人全称'},
                {field:'bankname',title:'收款人开户银行'}
            ]],
            onChange: function(){
                var g = $('#bankid').combogrid('grid').datagrid('getSelected');	// get datagrid object
                if(g!=null){
                    $('#payeraccocunt').textbox('setValue', g.accountcode);
                }
            }
        });
        $('#itemid').combobox({
            editable: false,
            data: []
        });
        $('#unitid').combobox({
            editable: false,
            data: [],
            onChange: function(){
                var val = $('#unitid').combobox('getValue');
                $('#itemid').combobox({
                    url:prefix + '/base/basedata/findUnitVsItemView?unitid='+val,
                    valueField:'itemid',
                    textField:'itemname'
                });
            }
        });
        //---区划三级下拉框
        $('#cantonid').combotree({
            url:prefix+'/base/basedata/findUserCantonMap',
            width: 180,
            onChange: function(){
                var t = $('#cantonid').combotree('getValue');	// get the tree object
                $('#unitid').combobox({
                    url:prefix + '/base/basedata/findUnitCantonId?cantonid='+t,
                    valueField:'unitid',
                    textField:'unitname'
                });
            }
        })
        // 发送复核表格
        $('#SendMainGrid').datagrid({
            pagination: false,
            fitColumns:false,
            striped: true,
            singleSelect: false,
            loadMsg: "正在加载数据，请稍后...",
            columns:[[
                {title: '行政区划', field: 'cantonname', width: 80},
                {title: '付款单位', field: 'unitname'},
                {title: '付款项目', field: 'itemname'},
                {title: '付款户名', field: 'payerbank'},
                {title: '付款银行账号', field: 'payeraccount', width: 140},
                {title: '收款人', field: 'payeeaccountname'},
                {title: '收款人账号', field: 'payeeaccountnum', width: 140},
                {title: '金额', field: 'originfund', width: 80},
                {title: '交易日期', field: 'paybankdt', width: 130},
                {title: '流水号', field: 'bankaffirm'},
                {title: '附言', field: 'postscript', width: 100}
            ]]
        });
    });

    function searchInfo() {
        if ($('#accountcode').val() == '') {
            $.messager.alert('提示', '请选择缴款账户', 'info');
            return;
        }
        $('#MainGrid').datagrid('load', {
            accountcode: $('#accountcode').val(),
            paybankdt: $('#paybankdtfind').val(),
            bankaffirm: $('#bankaffirmfind').val()
        });
    }

    function removeInfo() {
        row = $('#MainGrid').datagrid('getSelections');
        if (row.length == 0) {
            $.messager.alert('提示', '请选择要发送的数据', 'info');
            return;
        }
        var list = [];
        $.each(row,function(index, value) {
            list.push(value.waitaffirmpayid);
        });

        $.messager.confirm('确认', '您确认想要删除记录吗？', function (r) {
            if (r) {
                $.ajax({
                    url: prefix + '/bill/waitaffirmpayinfo/deleteWaitaffirmPayInfo',
                    type: 'POST',
                    data: {waitaffirmpayids: list.toString()},
                    dataType: 'json',
                    success: function (data) {
                        searchInfo();
                        $.messager.alert('提示', data.msg, 'info');
                    }
                });
            } else {//没选中
                return false;
            }
        })
    }

    function sendInfo() {
        $('#usercode').textbox('setValue', '');
        $('#userpwd').textbox('setValue', '');
        var row = $('#MainGrid').datagrid('getSelections');
        if (row.length == 0) {
            $.messager.alert('提示', '请选择要发送的数据', 'info');
            return;
        }
        var tit = '发送99支出';
        $('#sendClean').text('确认发送');

        $( "#SendBox-add" ).removeClass('hide').dialog({
            title: '&nbsp;'+tit,
            iconCls:'icon-send',
            width: 600,
            height: 500,
            modal: true,
            buttons:[{
                text:'取消',
                iconCls:'icon-cancel',
                width:80,
                plain:false,
                handler:function(){$('#SendBox-add').dialog('close')}
            }]
        });

        // 右侧表格
        $('#SendMainGrid').datagrid({
            data:row,
        });
    }

    //  ----------------确认发送
    function pageSendInfo() {
        var usercode = $('#usercode').val();
        var userpwd = $('#userpwd').val();
        if (usercode == null || usercode == '') {
            $.messager.alert('提示', '请输入用户编码', 'info');
            return;
        }
        if (userpwd == null || userpwd == '') {
            $.messager.alert('提示', '请输入用户密码', 'info');
            return;
        }
        var row = $('#SendMainGrid').datagrid('getData');
        var list = [];
        $.each(row.rows, function (index, value) {
            list.push(value.waitaffirmpayid)
        });
        $.messager.progress({
           title: '提示',
           msg: '数据处理中，请稍候……',
           text: ''
       });
        $.ajax({
            url: prefix + '/bill/waitaffirmpayinfo/sendWaitaffirmPayInfo',
            type: 'POST',
            data: {
                usercode: usercode,
                userpwd: userpwd,
                billids: list.toString()
            },
            dataType: 'json',
            success:function(data){
                $.messager.alert('提示', data.msg, 'info', function() {
                    if (data.success) $('#SendBox-add').dialog('close');
                    $.messager.progress('close');
                });
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                $.messager.alert('提示', '提交失败', 'info');
                $.messager.progress('close');
            }
        });

    }

    //取消关闭发送窗口
    function cancelInfo() {
        $('#SendBox-add').dialog('close')
    }

    function editInfo(opt) {
        if (opt==1) {
            $('#bankid').combo('readonly', false);
            clearForm();
        }else{
            $('#bankid').combo('readonly', true);
            $('#paybankdt').textbox('readonly', true);
            var rows = $('#MainGrid').datagrid('getSelections');
            if (rows.length ==0) {
                $.messager.alert('提示', '请选择要编辑的数据', 'info');
                return;
            }
            if (rows.length>1) {
                $.messager.alert('提示', '修改操作不能多选', 'info');
                return;
            }
            console.log(rows[0]);
            $('#form-update').form('load',rows[0]);
        }
        showForm(opt);
    }

    function clearForm() {
        $('#form-update').form('clear');
        $('#unitid').combobox('clear');
        $('#itemid').combobox('clear');
    }


    function showForm(opt) {
        var tit = (opt == 2) ? '修改99支出' : '新增99支出';
        $("#box-update").removeClass('hide').dialog({
            title: '&nbsp;' + tit,
            iconCls: 'icon-add',
            width: 800,
            height: 500,
            modal: true,
            buttons: [{
                text: '保存',
                iconCls: 'icon-ok',
                width: 80,
                plain: false,
                handler: function () {
                    updateInfo(opt);
                }
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                width: 80,
                plain: false,
                handler: function () {
                    $('#box-update').dialog('close')
                }
            }]
        });
    }
    //待查新增修改
    function updateInfo(opt) {
        var url = (opt ==2) ? '/bill/waitaffirmpayinfo/saveWaitaffirmPayInfo' :'/bill/waitaffirmpayinfo/insertaffirmPayInfo';
        $('#form-update').form({
            url: prefix + url,
            onSubmit:function(){
                var isValid = $(this).form('validate');
                if (isValid){
                    $.messager.progress({
                        title: '提示',
                        msg: '数据处理中，请稍候……',
                        text: ''
                    });
                }
                return isValid;
            },
            success:function(data) {
                $.messager.progress('close');
                var data = eval('(' + data + ')');
                if (data.success) {
                    searchInfo();
                    $('#box-update').dialog('close');
                }
                $.messager.alert('提示', data.msg, 'info');
            }
        });
        $('#form-update').submit();
    }


</script>
</body>
</html>
